﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EntityModule
{
    public class UserService
    {
        public SportDataContext Service { get { return EntityService.Instance(); } }

        public void Insert(User obj)
        {
            obj.ID = Guid.NewGuid();
            Service.Users.InsertOnSubmit(obj);
            Service.SubmitChanges();
        }
        public void Update()
        {
            Service.SubmitChanges();
        }
        public User GetUser (string username,string pass)
        {
            username = username.Trim();
            pass = Common.GetMD5(username.Trim());
            return Service.Users.FirstOrDefault(s => s.Name == username && s.Password == pass);
        }
        public List<User> GetUser(int page, int pageSize)
        {
            List<User> news = Service.Users.Where(s => s.IsDel == null).Skip(page * pageSize).Take(pageSize).ToList();
            return news;
        }

        public User GetUser(Guid guid)
        {
            return Service.Users.FirstOrDefault(s => s.ID == guid);
        }
    }
}
